<!--{template /module/admin/view/head}-->
<div id="left_layout">
	<div id="main_content" class="container-fluid container-fluid-thin">
		<div class="row-fluid">
			<div class="well widget">
				<div class="widget-header">
					<h3 class="title">{lang cms.article.view.header}</h3>
				</div>
				<div class="widget-content">
					<form class="form-search" id="frm_search" name="frmSearch" action="{$ADMIN_SCRIPT}/cms/article/_list&cid={$_var[gp_cid]}" method="post">
					<div class="action-wrapper">
						<div class="pull-left">
							<a href="javascript:void(null);" id="btn_delete_list" class="btn btn-small" {$dispatches[operations][delete]}>{lang admin.operation.delete}</a>
							<a href="javascript:void(null);" id="btn_move_list" class="btn btn-small" {$dispatches[operations][move]}>{lang admin.operation.move}</a>
							
							<!--{if count($subjects) > 0}-->
							<a href="javascript:void(null);" id="btn_send_list" class="btn btn-small" {$dispatches[operations][send]}>{lang admin.operation.send}</a>
							<!--{/if}-->
							
							<a href="javascript:void(null);" id="btn_copy_list" class="btn btn-small" {$dispatches[operations][copy]}>{lang admin.operation.copy}</a>
							<a href="javascript:void(null);" id="btn_thumb_list" class="btn btn-small" {$dispatches[operations][edit]}>{lang cms.article.view.operation.thumb}</a>
							<a href="{$ADMIN_SCRIPT}/cms/article/_pub&cid={$_var[gp_cid]}" {$dispatches[operations][add]} class="btn btn-small">{lang cms.article.view.operation.add}</a>
						</div>
						<div class="pull-right" {$dispatches[operations][search]}>
							<div class="input-append">
								<input type="text" name="txtKeyword" value="{$_var[gp_txtKeyword]}" class="input-small search-query" />
								<button type="submit" class="btn">{lang admin.search.submit}</button>
							</div>
							<button type="button" state="0" class="btn" id="btn_extend_search">{lang admin.search.submit.extend}<i class="micon-arrow-down"></i></button>
						</div>
					</div>
					</form>
					
					<div id="div_extend_search" style="display:none;">
						<hr/>
						<form id="frm_extend_search" name="frmExtendSearch" action="{$ADMIN_SCRIPT}/cms/article/_list&cid={$_var[gp_cid]}" method="post">
						<input type="hidden" name="hdnSearchShow" id="hdnSearchShow" value="1" />
						<table>
						<tr>
							<td width="46">{lang admin.search.keyword}</td>
							<td>
								<label class="checkbox inline">
									<input type="text" name="txtKeyword" value="{$_var[gp_txtKeyword]}" class="input-small" />
								</label>
								<label class="checkbox inline">
								<select name="sltType">
						            <option value="0" {if $_var['gp_sltType'] == 0}selected="selected"{/if}>{lang cms.article.view.search.type.option.0}</option>
						            <option value="1" {if $_var['gp_sltType'] == 1}selected="selected"{/if}>{lang cms.article.view.search.type.option.1}</option>
						            <option value="2" {if $_var['gp_sltType'] == 2}selected="selected"{/if}>{lang cms.article.view.search.type.option.2}</option>
						            <option value="3" {if $_var['gp_sltType'] == 3}selected="selected"{/if}>{lang cms.article.view.search.type.option.3}</option>
						            <option value="4" {if $_var['gp_sltType'] == 4}selected="selected"{/if}>{lang cms.article.view.search.type.option.4}</option>
						            <option value="5" {if $_var['gp_sltType'] == 5}selected="selected"{/if}>{lang cms.article.view.search.type.option.5}</option>
						            <option value="6" {if $_var['gp_sltType'] == 6}selected="selected"{/if}>{lang cms.article.view.search.type.option.6}</option>
						            <option value="7" {if $_var['gp_sltType'] == 7}selected="selected"{/if}>{lang cms.article.view.search.type.option.7}</option>
					            </select>
					            </label>
					            <label class="checkbox inline">
					            <select name="sltIsAudit">
						            <option value="0">{lang cms.article.view.search.isaudit.option.0}</option>
						            <option value="1" {if $_var['gp_sltIsAudit'] == 1}selected="selected"{/if}>{lang cms.article.view.search.isaudit.option.1}</option>
						            <option value="2" {if $_var['gp_sltIsAudit'] == 2}selected="selected"{/if}>{lang cms.article.view.search.isaudit.option.2}</option>
					            </select>
					            </label>
					            <label class="checkbox inline">
					            <select name="sltIsTop">
						            <option value="0">{lang cms.article.view.search.istop.option.0}</option>
						            <option value="1" {if $_var['gp_sltIsTop'] == 1}selected="selected"{/if}>{lang cms.article.view.search.istop.option.1}</option>
						            <option value="2" {if $_var['gp_sltIsTop'] == 2}selected="selected"{/if}>{lang cms.article.view.search.istop.option.2}</option>
					            </select>
					            </label>
					            <label class="checkbox inline">
					            <select name="sltIsCommend">
						            <option value="0">{lang cms.article.view.search.iscommend.option.0}</option>
						            <option value="10" {if $_var['gp_sltIsCommend'] == 10}selected="selected"{/if}>{lang cms.article.view.search.iscommend.option.10}</option>
						            <option value="9" {if $_var['gp_sltIsCommend'] == 9}selected="selected"{/if}>{lang cms.article.view.search.iscommend.option.9}</option>
							        <option value="8" {if $_var['gp_sltIsCommend'] == 8}selected="selected"{/if}>{lang cms.article.view.search.iscommend.option.8}</option>
							        <option value="7" {if $_var['gp_sltIsCommend'] == 7}selected="selected"{/if}>{lang cms.article.view.search.iscommend.option.7}</option>
							        <option value="6" {if $_var['gp_sltIsCommend'] == 6}selected="selected"{/if}>{lang cms.article.view.search.iscommend.option.6}</option>
							        <option value="5" {if $_var['gp_sltIsCommend'] == 5}selected="selected"{/if}>{lang cms.article.view.search.iscommend.option.5}</option>
							        <option value="4" {if $_var['gp_sltIsCommend'] == 4}selected="selected"{/if}>{lang cms.article.view.search.iscommend.option.4}</option>
							        <option value="3" {if $_var['gp_sltIsCommend'] == 3}selected="selected"{/if}>{lang cms.article.view.search.iscommend.option.3}</option>
							        <option value="2" {if $_var['gp_sltIsCommend'] == 2}selected="selected"{/if}>{lang cms.article.view.search.iscommend.option.2}</option>
							        <option value="1" {if $_var['gp_sltIsCommend'] == 1}selected="selected"{/if}>{lang cms.article.view.search.iscommend.option.1}</option>
					            </select>
					            </label>
					            <label class="checkbox inline">
					            <select name="sltHasImage">
						            <option value="0">{lang cms.article.view.search.hasimage.option.0}</option>
						            <option value="1" {if $_var['gp_sltHasImage'] == 1}selected="selected"{/if}>{lang cms.article.view.search.hasimage.option.1}</option>
						            <option value="2" {if $_var['gp_sltHasImage'] == 2}selected="selected"{/if}>{lang cms.article.view.search.hasimage.option.2}</option>
					            </select>
					            </label>
					            <label class="checkbox inline">
					            <select name="sltHasCategory">
						            <option value="0">{lang cms.article.view.search.hascategory.option.0}</option>
						            <option value="1" {if $_var['gp_sltHasCategory'] == 1}selected="selected"{/if}>{lang cms.article.view.search.hascategory.option.1}</option>
						            <option value="2" {if $_var['gp_sltHasCategory'] == 2}selected="selected"{/if}>{lang cms.article.view.search.hascategory.option.2}</option>
					            </select>
					            </label>
							</td>
						</tr>
						<tr>
							<td>{lang admin.search.time}</td>
							<td>
								<input type="text" name="txtBeginDate" maxlength="16" class="input-medium input-date" value="{$_var[gp_txtBeginDate]}" />
					            {lang admin.search.to}
					            <input type="text" name="txtEndDate" maxlength="16" class="input-medium input-date" value="{$_var[gp_txtEndDate]}" />
					            <label class="checkbox inline">
					            <select name="sltSort">
						            <option value="0">{lang cms.article.view.search.sort.option.0}</option>
						            <option value="1" {if $_var['gp_sltSort'] == 1}selected="selected"{/if}>{lang cms.article.view.search.sort.option.1}</option>
						            <option value="2" {if $_var['gp_sltSort'] == 2}selected="selected"{/if}>{lang cms.article.view.search.sort.option.2}</option>
						            <option value="3" {if $_var['gp_sltSort'] == 3}selected="selected"{/if}>{lang cms.article.view.search.sort.option.3}</option>
						            <option value="4" {if $_var['gp_sltSort'] == 4}selected="selected"{/if}>{lang cms.article.view.search.sort.option.4}</option>
					            </select>
					            </label>
							</td>
						</tr>
						<tr>
							<td>{lang cms.article.view.search.expried.label}</td>
							<td>
								<input type="text" name="txtSExpried" maxlength="16" class="input-medium input-date" value="{$_var[gp_txtSExpried]}" />
							</td>
						</tr>
						<tr>
							<td></td>
							<td>
								<button type="submit" class="btn btn-primary">{lang admin.search.submit.extend.submit}</button>
							</td>
						</tr>
						</table>
			            </form>
					</div>
					
					<hr/>
					<form id="frm_grid" name="frmGrid" action="{$ADMIN_SCRIPT}/cms/article/_list&cid={$_var[gp_cid]}&page={$_var[page]}&psize={$_var[psize]}{$search[querystring]}" method="post">
					<input type="hidden" name="hdnSubjectID" value="0"/>
					<input type="hidden" name="hdnMoveCategoryID" value="0"/>
					<input type="hidden" name="hdnCopyCategoryID" value="0"/>
					<input type="hidden" name="hdnConvertType" value="-1"/>
					<table class="table table-hover">
						<thead>
							<tr>
								<th width="30"><input type="checkbox" class="fancy" name="cbxAll"/></th>
								<th width="115">{lang cms.article.view.th.cname}</th>
					            <th>{lang cms.article.view.th.title}</th>
					            <th width="120">{lang cms.article.view.th.username}/{lang cms.article.view.th.edittime}</th>
					            <th width="60">{lang cms.article.view.th.state}</th>
					            <th width="40">{lang cms.article.view.th.istop}/{lang cms.article.view.th.iscommend}</th>
					            <th width="90">{lang cms.article.view.th.operation}</th>
							</tr>
						</thead>
						<tbody>
							<!--{loop $articles $_loop $article}-->
							<tr class="item-row">
							<td>
				        		<input type="checkbox" class="fancy" name="cbxItem[]" title="{$article[TITLE]}" value="{$article[ARTICLEID]}"/>
				            </td>
				            <td class="f10">
				            	{$article[CNAME]}
				            </td>
				            <td>
				            	<p class="text-info thin">
						            <a href="{$ADMIN_SCRIPT}/cms/article/_view&id={$article[ARTICLEID]}&ref=thin&page={$_var[page]}&psize={$_var[psize]}{$search[querystring]}" class="{echo $article['ISAUDIT'] == 1 ? 'text-success' : 'text-error';} f14">{$article[TITLE]}</a>
						            <span class="f10">
							            [{echo substr($article[PUBDATE], 0, 16);}]
							            ID:{$article[ARTICLEID]}
							            <!--{if $article['EXPRIED'] + 0 > 0}-->
							            <em class="muted">
							            	<small>({echo substr($article['EXPRIED'], 0, 10);}过期)</small>
							            </em>
							            <!--{/if}-->
						            </span>
					            </p>
					            
					            <!--{if $article['KEYWORDS'] && !$article['COLUMNS']['KEYWORDS']['hidden']}-->
					            <p class="muted f12 thin">
					            	[
					            		<!--{if $article['COLUMNS']['KEYWORDS']['text']}-->
					            		{$article[COLUMNS][KEYWORDS][text]}
					            		<!--{else}-->
					            		{lang cms.article_audit.view.td.columns.keywords}
					            		<!--{/if}-->
					            	] {$article[KEYWORDS]}
					            </p>
					            <!--{/if}-->
					            
					            <!--{if $article['MODULE'] && !strexists($article['MODULE'], 'empty')}-->
					            <p class="muted f12 thin">
					            	{lang cms.article.view.th.module}{$article[MODULE]}
					            </p>
					            <!--{/if}-->
				            </td>
				            <td class="f10">
					            {$article[USERNAME]}<br/>
					            {echo substr($article[EDITTIME], 0, 16);}
				            </td>
				            <td class="f10">
					            {$article[HITS]}{lang cms.article.view.td.stat.hits}
					            <!--{if $article['LEVEL']}--><br/>{$article[LEVEL]}{lang cms.article.view.td.stat.level}<!--{/if}-->
					            <!--{if $article['ATTENT']}--><br/>{$article[ATTENT]}{lang cms.article.view.td.stat.attent}<!--{/if}-->
					            <!--{if $article['UP']}--><br/>{$article[UP]}{lang cms.article.view.td.stat.up}<!--{/if}-->
					            <!--{if $article['DOWN']}--><br/>{$article[DOWN]}{lang cms.article.view.td.stat.down}<!--{/if}-->
				            </td>
				            <td>
					            <!--{if $article['ISTOP'] == 1}-->
					            <span class="text-success">{lang cms.article.view.td.istop.yes}</span>
					            <!--{else}-->
					            <span class="muted">{lang cms.article.view.td.istop.no}</span>
					            <!--{/if}-->
					            <br/>
					            <!--{if $article['ISCOMMEND'] > 0}-->
					            <span class="text-success">{$article[ISCOMMEND]}{lang cms.article.view.td.iscommend.yes}</span>
					            <!--{else}-->
					            <span class="muted">{lang cms.article.view.td.iscommend.no}</span>
					            <!--{/if}-->
				            </td>
				            <td>
					            <a class="btn btn-mini btn-primary" href="{$ADMIN_SCRIPT}/cms/article/_update&id={$article[ARTICLEID]}&ref=thin&page={$_var[page]}&psize={$_var[psize]}{$search[querystring]}" {$dispatches[operations][edit]}>{lang admin.operation.edit}</a>
					            <a class="btn btn-mini btn-delete" title="{$article[TITLE]}" data="{$article[ARTICLEID]}" href="javascript:void(null);" {$dispatches[operations][delete]}>{lang admin.operation.delete}</a>
				            </td>
				            </tr>
				            <!--{/loop}-->
				            <!--{if $count == 0}-->
					        <tr>
					            <td colspan="7">
					                * {lang admin.operation.empty}
					            </td>
					        </tr>
					        <!--{/if}-->
						</tbody>
					</table>
					</form>
					
					<hr/>
					{$pager}
				</div>
			</div>
		</div>
	</div>
</div>

<script>
function get_move_select_list(id, slt){
	var index = slt == null ? -1 : slt.selectedIndex;
	var pid = index != -1  ? slt.options[index].value : '0';
	var node = $('#' + id).get(0);
	
	var hdn = $('#hdn_move_categoryid').get(0);
	hdn.value = pid;
	
	var idarray = pid.split(',');
	pid = idarray[0];
		
	if(pid == '-1'){
		node.innerHTML = '';
		return;
	}
	
 	$.getJSON('{$ADMIN_SCRIPT}/cms/article/_category&rnd=' + Math.random(), {parentid:pid}, function(data){
 		if(data.DATA.length == 0){
 			node.innerHTML = ''; 
 			return;
 		}
		
		node.innerHTML = '';
		node.innerHTML += "<select name=\"sltMove" + pid + "\" id=\"slt_move_" + pid + "\" onchange=\"get_move_select_list('tree_move_list_" + pid + "',this)\"></select>&nbsp;";
		node.innerHTML += "<span id=\"tree_move_list_" + pid + "\"></span>";
		
		var slt = $('#slt_move_' + pid).get(0);
		slt.options[0] = new Option('{lang cms.article.view.operation.category.option}', '-1');
		for(var i=0; i < data.DATA.length; i++){
			slt.options[i+1] = new Option(data.DATA[i].CNAME, data.DATA[i].CATEGORYID + ',' + data.DATA[i].CHILDREN);
		}
	});
}

function get_copy_select_list(id, slt){
	var index = slt == null ? -1 : slt.selectedIndex;
	var pid = index != -1  ? slt.options[index].value : '0';
	var node = $('#' + id).get(0);
	
	var hdn = $('#hdn_copy_categoryid').get(0);
	hdn.value = pid;
	
	var idarray = pid.split(',');
	pid = idarray[0];
		
	if(pid == '-1'){
		node.innerHTML = ''; 
		return;
	}
	
 	$.getJSON('{$ADMIN_SCRIPT}/cms/article/_category&rnd=' + Math.random(), {parentid:pid}, function(data){
 		if(data.DATA.length == 0){
 			node.innerHTML = ''; 
 			return;
 		}
		
		node.innerHTML = '';
		node.innerHTML += "<select name=\"sltCopy" + pid + "\" id=\"slt_copy_" + pid + "\" onchange=\"get_copy_select_list('tree_copy_list_" + pid + "',this)\"></select>&nbsp;";
		node.innerHTML += "<span id=\"tree_copy_list_" + pid + "\"></span>";
		
		var slt = $('#slt_copy_' + pid).get(0);
		slt.options[0] = new Option('{lang cms.article.view.operation.category.option}', '-1');
		for(var i=0; i < data.DATA.length; i++){
			slt.options[i+1] = new Option(data.DATA[i].CNAME, data.DATA[i].CATEGORYID + ',' + data.DATA[i].CHILDREN);
		}
	});
}

function search_toggle(){
	var state = $('#btn_extend_search').attr('state');
	if(state == '0'){
		$('#btn_extend_search').html('{lang admin.search.submit.extend.hide}<i class="micon-arrow-up"></i>').attr('state', '1');
	}else{
		$('#btn_extend_search').html('{lang admin.search.submit.extend}<i class="micon-arrow-down"></i>').attr('state', '0');
	}
	
	$('.pull-right .input-append').toggle();
	$('#div_extend_search').toggle();
}

$(function(){
	$('.fancy').uniform();
	$('.input-date').datepicker({format:'yyyy-mm-dd'});
	
	$('#btn_submit').click(function(){
		$('#frm_grid').submit();
	});
	
	$('#btn_move_list').click(function(){
		if($("#frm_grid input[name='cbxItem[]']:checked").length > 0){
			$.dialog({submit:'{lang admin.operation.move}', href:'{$ADMIN_SCRIPT}/cms/article/_move', callback:function(){
				$('#modal_dialog .btn-primary').click(function(){
					var idarr = $('#hdn_move_categoryid').val().trim().split(',');
					
					$("#frm_grid input[name='hdnMoveCategoryID']").val(idarr[0]);
					$('#frm_grid').attr('action', '{$ADMIN_SCRIPT}/cms/article/_list&do=move_list&page={$_var[page]}&psize={$_var[psize]}{$search[querystring]}');
					$('#frm_grid').submit();
					
					$('#modal_dialog').modal('hide').remove();
				});
				
				get_move_select_list('tree_move_list', null);
			}});
		}else $.dialog({message:'{lang cms.article.view.operation.empty}'});
	});
	
	$('#btn_copy_list').click(function(){
		if($("#frm_grid input[name='cbxItem[]']:checked").length > 0){
			$.dialog({submit:'{lang admin.operation.copy}', href:'{$ADMIN_SCRIPT}/cms/article/_copy', callback:function(){
				$('#modal_dialog .btn-primary').click(function(){
					var idarr = $('#hdn_copy_categoryid').val().trim().split(',');
					
					$("#frm_grid input[name='hdnCopyCategoryID']").val(idarr[0]);
					$("#frm_grid input[name='hdnConvertType']").val($('#slt_convert_type').val());
					$('#frm_grid').attr('action', '{$ADMIN_SCRIPT}/cms/article/_list&do=copy_list&page={$_var[page]}&psize={$_var[psize]}{$search[querystring]}');
					$('#frm_grid').submit();
					
					$('#modal_dialog').modal('hide').remove();
				});
				
				get_copy_select_list('tree_copy_list', null);
			}});
		}else $.dialog({message:'{lang cms.article.view.operation.empty}'});
	});
	
	$('#btn_send_list').click(function(){
		if($("#frm_grid input[name='cbxItem[]']:checked").length > 0){
			$.dialog({submit:'{lang admin.operation.send}', href:'{$ADMIN_SCRIPT}/cms/article/_send', callback:function(){
				$('#modal_dialog .btn-primary').click(function(){
					var subjectId = $('#slt_dialog_subjectid').val().trim();
					
					$("#frm_grid input[name='hdnSubjectID']").val(subjectId);
					$('#frm_grid').attr('action', '{$ADMIN_SCRIPT}/cms/article/_list&do=send_list&page={$_var[page]}&psize={$_var[psize]}{$search[querystring]}');
					$('#frm_grid').submit();
					
					$('#modal_dialog').modal('hide').remove();
				});
			}});
		}else $.dialog({message:'{lang cms.article.view.operation.empty}'});
	});
	
	$('#btn_thumb_list').click(function(){
		if($("#frm_grid input[name='cbxItem[]']:checked").length > 0){
			$.dialog({submit:'{lang cms.article.view.operation.thumb}', message:'<p>{lang cms.article.view.operation.thumb.message}</p>', callback:function(){
				$('#modal_dialog .btn-primary').click(function(){
					$('#frm_grid').attr('action', '{$ADMIN_SCRIPT}/cms/article/_list&do=thumb_list&page={$_var[page]}&psize={$_var[psize]}{$search[querystring]}');
					$('#frm_grid').submit();
					
					$('#modal_dialog').modal('hide').remove();
				});
			}});
		}else $.dialog({message:'{lang cms.article.view.operation.empty}'});
	});
	
	$('#btn_delete_list').click(function(){
		if($("#frm_grid input[name='cbxItem[]']:checked").length > 0){
			var tempHTML = '<p>';
			$("#frm_grid input[name='cbxItem[]']:checked").each(function(){
				tempHTML += $(this).attr('title') + '； ';
			});
			
			tempHTML += '</p>';
			
			$.dialog({submit:'{lang admin.operation.delete}', message:'<p>{lang cms.article.view.operation.delete.message}</p>' + tempHTML, callback:function(){
				$('#modal_dialog .btn-primary').click(function(){
					$('#frm_grid').attr('action', '{$ADMIN_SCRIPT}/cms/article/_list&do=delete_list&page={$_var[page]}&psize={$_var[psize]}{$search[querystring]}');
					$('#frm_grid').submit();
					
					$('#modal_dialog').modal('hide').remove();
				});
			}});
		}else $.dialog({message:'{lang cms.article.view.operation.empty}'});
	});
	
	$('#btn_extend_search').click(function(){
		search_toggle();
	});
	
	$("#frm_grid input[name='cbxAll']").click(function(){
		if(this.checked){
			$('#frm_grid .item-row').addClass('warning');
			$("#frm_grid input[name='cbxItem[]']").attr('checked', true).parent().addClass('checked');
		}else{
			$('#frm_grid .item-row').removeClass('warning');
			$("#frm_grid input[name='cbxItem[]']").attr('checked', false).parent().removeAttr('class');
		}
	});
	
	$("#frm_grid input[name='cbxItem[]']").click(function(){
		if(this.checked) $(this).parent().parent().parent().parent().addClass('warning');
		else $(this).parent().parent().parent().parent().removeClass('warning');
	});
	
	$('#frm_grid .btn-delete').click(function(){
		var articleid = $(this).attr('data');
		var tempHTML = '<p>' + $(this).attr('title') + '； </p>';
		
		$.dialog({submit:'{lang admin.operation.delete}', message:'<p>{lang cms.article.view.operation.delete.one}</p>' + tempHTML, callback:function(){
			$('#modal_dialog .btn-primary').click(function(){
				$('#frm_grid').attr('action', '{$ADMIN_SCRIPT}/cms/article/_list&do=delete&id=' + articleid + '&page={$_var[page]}&psize={$_var[psize]}{$search[querystring]}');
				$('#frm_grid').submit();
				
				$('#modal_dialog').modal('hide').remove();
			});
		}});
	});
	
	{if $_var[gp_hdnSearchShow]}
	search_toggle();
	{/if}
});
</script>
<!--{template /module/admin/view/foot}-->